import { login } from '@/api/user'

const state = {
  token: localStorage.getItem('token') || ''
}
const mutations = {
  setToken(state, data) {
    state.token = data
    localStorage.setItem('token', data)
  }
}
const actions = {
  async login(store, data) {
    const res = await login(data)
    console.log(res.data.jwt)
    store.commit('setToken', res.jwt)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
